package my.mark.mybaibaoxiang.twotiger.contract.utils;


/**
 * @Description: App工具类
 * @Author wxming
 * @Date 2015年7月9日 下午12:59:36 
 */
public class CommonUtil {

    /**
     * 前3+后3
     * 
     * @param phone
     * @return
     */
    public static String maskPhone(String phone) {
        StringBuilder sb = new StringBuilder("");
        char[] tmps = phone.toCharArray();
        for (int i = 0; i < tmps.length; i++) {
            if (i < 3 || i > (tmps.length - 4)) {
                sb.append(tmps[i]);
            } else {
                sb.append('*');
            }
        }
        return sb.toString();
    }

    /**
     * 前1 
     * @param name
     * @return
     */
    public static String maskName(String name) {
        StringBuilder sb = new StringBuilder("");
        char[] tmps = name.toCharArray();
        for (int i = 0; i < tmps.length; i++) {
            if (i < 1) {
                sb.append(tmps[i]);
            } else {
                sb.append('*');
            }
        }
        return sb.toString();
    }

    /**
     * 前6+后4
     * @param idCard
     * @return
     */
    public static String maskIdCard(String idCard) {
        StringBuilder sb = new StringBuilder("");
        char[] tmps = idCard.toCharArray();
        for (int i = 0; i < tmps.length; i++) {
            if (i < 6 || i > (tmps.length - 5)) {
                sb.append(tmps[i]);
            } else {
                sb.append('*');
            }
        }
        return sb.toString();
    }
    
    /**
     * 前2+后2
     * @param address
     * @return
     */
    public static String maskAddress(String address) {
        StringBuilder sb = new StringBuilder("");
        char[] tmps = address.toCharArray();
        for (int i = 0; i < tmps.length; i++) {
            if (i < 2 || i > (tmps.length - 3)) {
                sb.append(tmps[i]);
            } else {
                sb.append('*');
            }
        }
        return sb.toString();
    }
    
    /**
     * 前2+后2
     * @param company
     * @return
     */
    public static String maskCompany(String company) {
        StringBuilder sb = new StringBuilder("");
        char[] tmps = company.toCharArray();
        for (int i = 0; i < tmps.length; i++) {
            if (i < 2 || i > (tmps.length - 3)) {
                sb.append(tmps[i]);
            } else {
                sb.append('*');
            }
        }
        return sb.toString();
    }
    
    public static void main(String[] args) {
        System.out.println(maskIdCard("130182198310200112"));
        System.out.println(maskPhone("13901234567"));
        System.out.println(maskName("阿打算联"));
    }

}